<%@ page language="java" import="com.demo.util.Conn,java.sql.ResultSet" pageEncoding="UTF-8"%>
<%
String cname = request.getParameter("companyname");
String jtitle = request.getParameter("jtitle");

String pageNum = request.getParameter("page");
pageNum = "".equals(pageNum) || pageNum == null ? "1" : pageNum;
int pageSize = 20;

String sql = " from dbf_job_info where 1=1 ";
if (!"".equals(cname) && cname != null)
	sql = sql + " and company_name like '" + cname + "%'";
if (!"".equals(jtitle) && jtitle != null) 
	sql = sql + " and job_title like'" + jtitle + "%'";

String sqlCount = "select count(*) as cnt " + sql;
sql = "select * " + sql + " limit " + (Integer.valueOf(pageNum).intValue() - 1) * 20 + "," + pageSize;

Conn conn = new Conn();
ResultSet rs = conn.find(sqlCount);
rs.next();
int count = rs.getInt("cnt");
rs.close();
rs = conn.find(sql);
cname = cname == null ? "" : cname;
jtitle = jtitle == null ? "" : jtitle;
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>职位搜索</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
  	<link rel="stylesheet" type="text/css" href="../style.css">
  </head>

  <body>
  <table width="718" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="39" colspan="3" background="../images/main_title.jpg"><strong><span class="menutitle">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Job Search</span></strong></td>
    </tr>
    <tr>
      <td valign="bottom"><img src="../images/menu_a.jpg" width="19" height="23" /></td>
      <td valign="top">&nbsp;</td>
      <td valign="bottom"><img src="../images/menu_b.jpg" width="18" height="23" /></td>
    </tr>
    <tr>
      <td width="19" valign="top" background="../images/menu_c.jpg"><img src="../images/menu_c.jpg" width="19" height="54" /></td>
      <td width="681" valign="top"><form action="jobs.jsp">
  				<table border="0" cellpadding="0" cellspacing="0" class="logintxt" style="width:100%">
  					<tr>
   						<td colspan="5" style="text-align:right">
  							Total <%=count %> Record(s)&nbsp;&nbsp;&nbsp;&nbsp;
  							<%="1".equals(pageNum) ? "First" : "<a href=\"jobs.jsp?page=1&companyname=" + cname + "&jtitle=" + jtitle + "\">First</a>" %>&nbsp;&nbsp;
  							<%="1".equals(pageNum) ? "Previous" : "<a href=\"jobs.jsp?page=" + String.valueOf(Integer.valueOf(pageNum).intValue() - 1) + "&companyname=" + cname + "&jtitle=" + jtitle + "\">Previous</a>" %>&nbsp;&nbsp;
  							<%=((Integer.valueOf(pageNum).intValue() * pageSize)) < count ? "<a href=\"jobs.jsp?page=" + String.valueOf(Integer.valueOf(pageNum).intValue() + 1) + "&companyname=" + cname + "&jtitle=" + jtitle + "\">Next</a>" : "Next" %>&nbsp;&nbsp;
  							<%=((Integer.valueOf(pageNum).intValue() * pageSize)) >= count ? "Last" : "<a href=\"jobs.jsp?page=" + (count % pageSize == 0 ? count / pageSize : count / pageSize + 1) + "&companyname=" + cname + "&jtitle=" + jtitle + "\">Last</a>" %>
  						</td>
  					</tr>
  					<tr><td colspan="5" height="5"></td></tr>
  					<tr>
  						<th style="background-color:#FFC963">Company Name </th>
  						<th style="background-color:#FFC963">Job Post</th>
  						<th style="background-color:#FFC963">Start Date</th>
  						<th style="background-color:#FFC963">End Date</th>
  						<th style="background-color:#FFC963">Available</th>
  						<th style="background-color:#FFC963"></th>
  					</tr>
  					<%
  						while(rs.next()) {
  					%>
  						<tr>
  							<td><%=rs.getString("company_name") %></td>
  							<td><%=rs.getString("job_title") %></td>
  							<td><%=rs.getString("job_starting_date") %></td>
  							<td><%=rs.getString("application_deadline") %></td>
  							<td><%=rs.getString("persion_num") %></td>
	    					<td><a href='jobs_del_commit.jsp?job_id=<%=rs.getString("job_id") %>'>delete</a></td>
  							
  						</tr>
  					<%} %>
  					<tr><td colspan="5" height="20">&nbsp;</td></tr>
  					<tr>
  						<td align="right">Company：</td>
  						<td align="left"><input type="text" name="companyname" /></td>
  						<td align="right">Job：</td>
					  <td align="left"><input type="text" name="jtitle" />&nbsp;&nbsp;&nbsp;&nbsp;
					    <input name="image" type="image"  value="search" src="../images/search_btn.jpg" /></td>
  					</tr>
		</table>
  				</form></td>
      <td width="18" valign="top" background="../images/menu_d.jpg"><img src="../images/menu_d.jpg" width="18" height="54" /></td>
    </tr>
    <tr>
      <td><img src="../images/menu_e.jpg" width="19" height="25" /></td>
      <td background="../images/menu_f.jpg"><img src="../images/menu_f.jpg" width="181" height="25" /></td>
      <td><img src="../images/menu_g.jpg" width="18" height="25" /></td>
    </tr>
  </table>
  </body>
</html>
